/*
 * Copyright 2010-2011 CGT&DC ISA RAS
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package websolve.workflow.runtime;

public class Parameter {

    private String type;
    private Object value;
    private boolean isConnected = false;
    private boolean isCancelled = false;
    private boolean isFailed = false;
    private int consumerCount = 0;

    public Parameter() {
    }

    public Parameter(String type) {
        this.type = type;
    }

    public Parameter(String type, Object value) {
        this.type = type;
        this.value = value;
    }

    public String getType() {
        return type;
    }

    public Object getValue() {
        return value;
    }

    public Parameter setValue(Object value) {
        this.value = value;
        return this;
    }

    public boolean isConnected() {
        return isConnected;
    }

    public boolean isCancelled() {
        return isCancelled;
    }

    public boolean isFailed() {
        return isFailed;
    }

    public boolean isReady() {
        if (value != null) {
            return true;
        } else {
            return false;
        }
    }

    protected void setConnected(boolean isConnected) {
        this.isConnected = isConnected;
    }

    public void setCancelled(boolean isCancelled) {
        this.isCancelled = isCancelled;
    }

    protected void setFailed(boolean isFailed) {
        this.isFailed = isFailed;
    }

    public boolean isCompatibleWith(Parameter param) {
        // if (this.type == null || (this.type.equals(param.getType()))) {
        return true;
        // } else {
        // return false;
        // }
    }

    public void incrementConsumerCount() {
        consumerCount++;
    }

    public void decrementConsumerCount() {
        consumerCount--;
    }

    public int getConsumerCount() {
        return consumerCount;
    }

}
